package com.cloud.entity;

import com.alibaba.fastjson.JSONObject;
import com.cloud.util.CommonUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Henry.Song
 * @version 2020/11/26
 * @description
 */
public class AlgorithmNotifyEntitiy extends JSONObject {
    public Integer getId() {
        return getIntValue("id");
    }

    public void setId(Integer id) {
        put("id", id);
    }

    public List<ConvertTaskFileEntity> getConvertedFiles() {

        if (getJSONArray("convertedFiles") == null) {
            setConvertedFiles(new ArrayList<ConvertTaskFileEntity>());
        }

        List<ConvertTaskFileEntity> files = new ArrayList<ConvertTaskFileEntity>();
        for(Object object : getJSONArray("convertedFiles").toArray()) {
            if (object instanceof ConvertTaskFileEntity) {
                files.add((ConvertTaskFileEntity)object);
            } else if (object instanceof Map) {
                ConvertTaskFileEntity fileEntity = new ConvertTaskFileEntity();
                CommonUtil.copyFromMap(fileEntity, (Map)object);
                files.add(fileEntity);
            }
        }
        return files;

        //return getObject("convertedFiles", new TypeReference<List<ConvertTaskFileEntity>>(){});
    }

    public void setConvertedFiles(List<ConvertTaskFileEntity> taskFiles) {
        put("convertedFiles", taskFiles);
    }

    public String getTaskStatus() {
        return getString("taskStatus");
    }

    public void setTaskStatus(String taskStatus) {
        put("taskStatus", taskStatus);
    }

    public Object getInfo() {
        return get("info");
    }
}
